$().ready(function() {
	$(".change-cities").fancybox({
        type: 'ajax',
        minHeight: 55,
        height: 75,
        width: 200,
        autoSize: false,
        topRatio: 0.15,
        tpl: {
        	closeBtn: '<a title="Закрыть" class="fancybox-item fancybox-close" href="javascript:;"></a>'
		}
    });

	
	$('[name="date_start"]').datepicker({
		dateFormat: 'yy-mm-dd',
		showAnim: 'blind',
		minDate: 0,
		onClose: function(selectedDate) {
			$('[name="date_end"]').datepicker("option", "minDate", $.datepicker.formatDate('yy-mm-dd', new Date(new Date(selectedDate).getTime() + (24 * 60 * 60 * 1000))));
		}
	});
	
	$('[name="date_end"]').datepicker({
		dateFormat: 'yy-mm-dd',
		showAnim: 'blind',
		minDate: 1
	});
	
	$('.search-form form').submit(function() {
		var cityId = $('[name="city"]').val();
		var countryId = $('[name="country"]').val();
		var adult = $('[name="adult"]').val();
		var children = $('[name="children"]').val();
		var nightFrom = $('[name="night_from"]').val();
		var nightTo = $('[name="night_to"]').val();
		var dateStart = $.datepicker.formatDate('dd.mm.yy', new Date($('[name="date_start"]').val()));
		var dateEnd = $.datepicker.formatDate('dd.mm.yy', new Date($('[name="date_end"]').val()));
		
		var url = 'http://sletat.ru/?callback=search&city=' + cityId + '&country=' + countryId + '&resort=&stars=&adults=' + adult + '&kids=' + children + '&kid1=2&kid2=2&kid3=2&operators=&nightsmin=' + nightFrom + '&nightsmax=' + nightTo + '&hotels=&pricesmin=&pricesmax=&datefrom=' + dateStart + '&dateto=' + dateEnd + '&currency=RUB&places=Y&hasflight=Y&hastickets=Y&meals=';
		
		window.location.href = url;
		return false;
	});
	
	$('.tour-block .hotel a').click(function() {
		$(this).next().slideToggle(300);
		return false;
	});
	
	$('.tour-block .poster').fancybox({
		hideOnContentClick: false,
		helpers: {
		    title : {
		        type : 'float'
		    }
		}
	});
	
	//window.open(document.URL, '_blank', 'location=yes,height=570,width=520,scrollbars=yes,status=yes');

	
//	$('[name="date_start"]').change(function() {
//		$('[name="date_end"]').focus();
//	});
	
	$('.gallery a').fancybox({
		openEffect	: 'none',
		closeEffect	: 'none'
	});
	
});